package com.lml.jdk8.test03;

import org.junit.jupiter.api.Test;

import java.util.Comparator;
import java.util.function.BiPredicate;
import java.util.function.Consumer;
import java.util.function.Supplier;

/**
 * @author Administrator
 * @date 2020/2/26 21:49
 * Description:
 */
public class TestMR {

    @Test
    void fun4() {
        BiPredicate<String, String> bp = (x, y) -> x.equals(y);
        System.out.println(bp.test("abc", "abc"));

        BiPredicate<String, String> bp2 = String::equals;
        System.out.println(bp2.test("abc", "abc"));
    }

    @Test
    void fun3() {
        //Lambda表达式写法:
        //Comparator<Integer> com = (x,y) -> Integer.compare(x,y);
        //类::静态方法
        Comparator<Integer> com = Integer::compare;
        System.out.println(com.compare(12, 14));
    }


    @Test
    void fun2() {
        Student s = new Student("lili", 18, 120);
        Supplier<String> supplier = s::getName;
        String str = supplier.get();
        System.out.println(str);
    }


    @Test
    void fun1() {
        /**
         * 分析:
         *      Lambda表达式实现的接口中的抽象方法: accept(传入参数) --> 没有返回值
         *      Lambda表达式的表达体中的具体的实现方法: println(传入参数) --> 没有返回值
         *      只要满足了:接口中的抽象方法 和 具体实现的方法 参数亿元,返回值一样
         *                就可以使用方法引用
         */

        //利用消费型接口,在打印台打印一句话
        /*PrintStream ps = System.out;
        Consumer<String> con = x -> ps.println(x);
        con.accept("welcome");*/

        //迭代2
        /*PrintStream ps = System.out;
        Consumer<String> con = ps::println;
        con.accept("welcome");*/

        Consumer<String> con = System.out::println;
        con.accept("welcome");

    }
}
